﻿#include "FITKGlobalFrequencyDomain.h"
#include <cmath>
#include <QDebug>

namespace Acoustics
{

    FITKGlobalFrequencyDomain::FITKGlobalFrequencyDomain()
    {
    }

    void FITKGlobalFrequencyDomain::setDomainType(DomainType t)
    {
        _domainType = t;
    }

    FITKGlobalFrequencyDomain::DomainType FITKGlobalFrequencyDomain::getDomainType()
    {
        return _domainType;
    }

    QList<double> FITKGlobalFrequencyDomain::getFrequenceList() const
    {
        QList<double> v;
        //根据不同的类型获取列表
        switch (_domainType)
        {
        case DTStandardOctave:
            v = this->getFrequenceListStandardOctave(); break;
        case DTStandard1Of3rdOctave:
            v = this->getFrequenceListStandard1Of3rdOctave(); break;
        case DTExact1OfnthOctave:
            v = this->getFrequenceListExact1OfnthOctave(); break;
        case  DTConstantBandWidth:
            v = this->getFrequenceListConstantBandWidth(); break;
        default: break;
        } 
        return v;
    }

    QList<double> FITKGlobalFrequencyDomain::getFrequenceListStandardOctave()const
    {
        //固定值，参考VAOne
        QList<double> fs{};
        fs << 2 << 4 << 8 << 16 << 31.5 << 63 << 125 << 250 << 500 << 1000 <<
            2e3 << 4e3 << 8e3 << 16e3 << 64e3 << 128e3;
        return fs;
    }

    QList<double> FITKGlobalFrequencyDomain::getFrequenceListStandard1Of3rdOctave()const
    {
         //固定值，参考VAOne
        QList<double> fs;
        fs << 1.25 << 1.6 << 2 << 2.5 << 3.15 << 4 << 5 << 6.3 << 8 << 10
            << 1.25e1 << 1.6e1 << 2e1 << 2.5e1 << 3.15e1 << 4e1 << 5e1 << 6.3e1 << 8e1 << 10e1
            << 1.25e2 << 1.6e2 << 2e2 << 2.5e2 << 3.15e2 << 4e2 << 5e2 << 6.3e2 << 8e2 << 10e2
            << 1.25e3 << 1.6e3 << 2e3 << 2.5e3 << 3.15e3 << 4e3 << 5e3 << 6.3e3 << 8e3 << 10e3
            << 1.25e4 << 1.6e4 << 2e4 << 2.5e4 << 3.2e4 << 4e4 << 5e4 << 6.4e4 << 8e4 << 10e4
            << 1.28e5 << 1.6e5;
        return fs;
    }

    QList<double> FITKGlobalFrequencyDomain::getFrequenceListExact1OfnthOctave()const
    {
        //默认值频率是1000
        const double f0 = 1000;
        const double n = _nthOctave;
        QList<double> fs{f0};

        int i = -1;
        double fc = f0;
        //小于1000的部分
        while (fc >1.25)
        {
            fc = pow(2.0, i / n)*f0;
            fs.insert(0, fc);
            i--;
        }
        //大于1000的部分
        i = 1; fc = f0;
        while (fc <160000)
        {
            fc = pow(2.0, i / n)*f0;
            fs.append(fc);
            i++;
        }
        return fs;
    }

    QList<double> FITKGlobalFrequencyDomain::getFrequenceListConstantBandWidth()const
    {
        QList<double> fs;
        //带宽太窄
        if (fabs(_bandWidth) < 1e-6) return fs;
        //固定带宽
        for (double v = _startFreq; v <= _endFreq ; v+= _bandWidth)
            fs.append(v);
        return fs;
    }

    void FITKGlobalFrequencyDomain::setOctaveNum(const int n)
    {
        _nthOctave = n;
    }

    int FITKGlobalFrequencyDomain::getOctaveNum() const
    {
        return _nthOctave;
    }

    void FITKGlobalFrequencyDomain::setStartFrequence(const double s)
    {
        _startFreq = s;
    }

    double FITKGlobalFrequencyDomain::getStartFrequence() const
    {
        return _startFreq;
    }

    void FITKGlobalFrequencyDomain::setEndFrequence(const double e)
    {
        _endFreq = e;
    }

    double FITKGlobalFrequencyDomain::getEndFrequence() const
    {
        return _endFreq;
    }

    void FITKGlobalFrequencyDomain::setBandWidth(const double w)
    {
        _bandWidth = w;
    }

    double FITKGlobalFrequencyDomain::getBandWidth() const
    {
        return _bandWidth;
    }




}



